import os
from google.appengine.api import urlfetch
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from models import Shelf
from tmdb import TMDb

class MovieSearchPage(webapp.RequestHandler):
    
    def post(self):
        
        self.redirect('/movie/search/%s' % self.request.get('q'))
    
    def get(self):
        
        self.response.out.write(template.render('templates/header.html', {}))
        self.response.out.write(template.render('templates/movie/search.html', {}))
        self.response.out.write(template.render('templates/footer.html', {}))

class MovieSearchResultsPage(webapp.RequestHandler):
    
    def get(self, q):
        
        tmdbapi = TMDb('58bdd901955465b24e37631dd9f68ced')
        results = tmdbapi.search(q)
        values = {'results':results}
        
        self.response.out.write(template.render('templates/header.html', {}))
        self.response.out.write(template.render('templates/movie/searchresults.html', values))
        self.response.out.write(template.render('templates/footer.html', {}))